//Group2
//COP4331C.0001
//BattleShip Project
//September 24th, 2009

//import all the necessary imports that will be used in the program
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//extend JApplet so that it will show up in an applet
//implement runnable to that it runs in the applet when opened
//implement MouseListener so that it will be able to respond to the clicks of the mouse
public class Battle extends JApplet implements Runnable, MouseListener, ActionListener
{
//define thread that will keep what has happened, on the screen, on the screen when covered
	private Thread drawingThread;
//define the variable stopped and set it to false when the program stops
	public boolean stopped = false;
//booleans that help determine whetehr your playing a 1 player game or a 2 player game
	public boolean oneplayergame = false;
	public boolean twoplayergame = false;
//define all necessary Buttons to be used on the pop up window
	private JFrame window;
	private LayoutManager layout;	
	private Canvas canvas;
//button for a 1 player game
	private JButton oneButton;
//button for a 2 player game
	private JButton twoButton;
//the button on the 1 player game to start the game after boats have been placed
	private JButton startButton;
//the button on the 2 player game to start the game after player 1's boats have been placed
	private JButton startoneButton;
//the button on the 2 player game to start the game after player 2's boats have been placed
	private JButton starttwoButton;
//button to display the instructions
	private JButton instructButton;
//button to return to the start screen from the instruction screen
	private JButton backButton;
//button to randomly place boats on the board on a one player game
	private JButton randomizeButton;
//button to randomly place boats on the board on a two player game for player 1
	private JButton randomizeoneButton;
//button to randomly place boats on the board on a two player game for player 2
	private JButton randomizetwoButton;
//button to individually place boats on the board on a one player game
	private JButton placeButton;
//button to individually place boats on the board on a two player game for player 1
	private JButton placeoneButton;
//button to individually place boats on the board on a two player game for player 2
	private JButton placetwoButton;

//variable to help determine whose turn it is
	int player = 0;
//variables to help determine where the boxes are displayed on the screen
	int [][] Xstart = new int [12][12];
	int [][] Ystart = new int [12][12];
	int [][] Xend = new int [12][12];
	int [][] Yend = new int [12][12];
	
//helps determine where the boats are located on the board	
//[amount of boats][number of players][i coordinate of boat section][j coordinate of boat section]
	int [][][][] XcoorFourBoat = new int [1][2][12][12];
	int [][][][] XcoorThreeBoat = new int [2][2][12][12];
	int [][][][] XcoorTwoBoat = new int [3][2][12][12];
	int [][][][] XcoorOneBoat = new int [4][2][12][12];

//keeps track of which spaces are clicked
	int [][][] clicked = new int [2][12][12];
	//0 = unclicked
	//1 = clicked

	
//keeps track of what is happening in each space
	int [][][] spottype = new int [2][12][12];
	//0 = nothing
	//1 = edge
	//2 = boat
	//3 = nexttoaboat
	//4 = hit
	//5 = sunkboat
	//6 = clicked
	//7 = miss
	
	
	

//method that is used in running the applet
	public void init()
	{
//initialize every spot on the board the unclicked and no activity, except for the edges
		for(int k = 0; k < 2; k++){
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					clicked[k][i][j] = 0;
					spottype[k][i][j] = 0;
				}
				else{
					clicked[k][i][j] = 1;
					spottype[k][i][j] = 1;
				}
			}	
			}
		}
//determines where each box is on the display, except for the edges		
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					Xstart[i][j] = (i*20) + 275; 
					Xend[i][j] = (i*20) + 275 + 20;
					Ystart[i][j] = (j-1)*20; 
					Yend[i][j] = (j-1)*20 + 20;
				}
				else{
					Xstart[i][j] = 0; 
					Xend[i][j] = 0;
					Ystart[i][j] = 0; 
					Yend[i][j] = 0;
				}
			}
		}
//creates the window, layout, canvas, and buttons (the instruction, 1 player, and 2 players buttons 
//being the only buttons visible at the start of the program)
				window = new JFrame("Battle Ship");
				layout = new FlowLayout();
				window.setLayout(layout);
				window.setSize(550,600);	
				canvas = new Canvas();
				canvas.setBackground(Color.WHITE);
				canvas.setSize(500, 500);
				canvas.addMouseListener(this);
				window.add(canvas);
				
				oneButton = new JButton("1 player");
				oneButton.addActionListener(this);
				window.add(oneButton);
				
				twoButton = new JButton("2 players");
				twoButton.addActionListener(this);
				window.add(twoButton);
				
				instructButton = new JButton("Instructions");
				instructButton.addActionListener(this);
				window.add(instructButton);
				
				startButton = new JButton("Start");
				startButton.addActionListener(this);
				window.add(startButton);
				startButton.setVisible(false);
				
				startoneButton = new JButton("Start");
				startoneButton.addActionListener(this);
				window.add(startoneButton);
				startoneButton.setVisible(false);
				
				starttwoButton = new JButton("Start");
				starttwoButton.addActionListener(this);
				window.add(starttwoButton);
				starttwoButton.setVisible(false);
				
				backButton = new JButton("Back");
				backButton.addActionListener(this);
				window.add(backButton);
				backButton.setVisible(false);
				
				randomizeButton = new JButton("Randomize");
				randomizeButton.addActionListener(this);
				window.add(randomizeButton);
				randomizeButton.setVisible(false);
				
				randomizeoneButton = new JButton("Randomize");
				randomizeoneButton.addActionListener(this);
				window.add(randomizeoneButton);
				randomizeoneButton.setVisible(false);
				
				randomizetwoButton = new JButton("Randomize");
				randomizetwoButton.addActionListener(this);
				window.add(randomizetwoButton);
				randomizetwoButton.setVisible(false);
				
				placeButton = new JButton("Place Boats");
				placeButton.addActionListener(this);
				window.add(placeButton);
				placeButton.setVisible(false);
				
				placeoneButton = new JButton("Place Boats");
				placeoneButton.addActionListener(this);
				window.add(placeoneButton);
				placeoneButton.setVisible(false);
				
				placetwoButton = new JButton("Place Boats");
				placetwoButton.addActionListener(this);
				window.add(placetwoButton);
				placetwoButton.setVisible(false);
				
				window.setVisible(true);
	}
	
//method that starts the applet	
	public void start()
	{
//define a new thread
		drawingThread = new Thread(this);
//set the stopped boolean to false
		stopped = false;
//tell the thread to start in the start method
		drawingThread.start();
	}
	
//method that will continue to run the applet	
	public void run()
	{
//at the start of the program, display "BATTLESHIP" on the canvas
		Graphics g = canvas.getGraphics();
		g.setColor(Color.BLACK);
		g.drawString("BATTLESHIP", 200, 250);
	}

//when window is closed stop the program from continuing to run	
	public void destroy()
	{
		stopped = true;
	}

//paint on the canvas when placing boats
	public void paint(int k)
	{
//for every box on the display, color in the correct color for what the activity is on that box
		Graphics g = canvas.getGraphics();
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
//if there is no activity on the box
				if(spottype[k][i][j] == 0){
					g.setColor(Color.CYAN);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box is an edge
				if(spottype[k][i][j] == 1){
					g.setColor(Color.WHITE);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box has a boat in it
				if(spottype[k][i][j] == 2){
					g.setColor(Color.YELLOW);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box has a boat next to it
				if(spottype[k][i][j] == 3){
					g.setColor(Color.BLUE);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box has been clicked on and a boat was in it (might be unnessary for this function)
				if(spottype[k][i][j] == 4){
					g.setColor(Color.RED);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the boat has been sunk (might be unnessary for this function)
				if(spottype[k][i][j] == 5){
					g.setColor(Color.BLACK);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
			}
		}
//draw the lines on the display to seperate each box from one another
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					g.setColor(Color.BLACK);
					g.drawRect(i*25, (j*25)+200, 25, 25);
				}
			}
		}
//draw numbers to determine which box is which
		g.setColor(Color.BLACK);
		g.drawString("1", 30, 220);
		g.drawString("2", 55, 220);
		g.drawString("3", 80, 220);
		g.drawString("4", 105, 220);
		g.drawString("5", 130, 220);
		g.drawString("6", 155, 220);
		g.drawString("7", 180, 220);
		g.drawString("8", 205, 220);
		g.drawString("9", 230, 220);
		g.drawString("10", 255, 220);
		g.drawString("1", 10, 240);
		g.drawString("2", 10, 265);
		g.drawString("3", 10, 290);
		g.drawString("4", 10, 315);
		g.drawString("5", 10, 340);
		g.drawString("6", 10, 365);
		g.drawString("7", 10, 390);
		g.drawString("8", 10, 415);
		g.drawString("9", 10, 440);
		g.drawString("10", 10, 465);
		
	}

//paint the boxes of your boats on the display
	public void paintgameyou(int k)
	{
		Graphics g = canvas.getGraphics();
//for every box on the display, color in the correct color for what the activity is on that box
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
//if the box has no activity or if there is a boat next to this box
				if((spottype[k][i][j] == 0) || (spottype[k][i][j] == 3)){
					g.setColor(Color.CYAN);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box is an edge
				if(spottype[k][i][j] == 1){
					g.setColor(Color.WHITE);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box has a boat in it
				if(spottype[k][i][j] == 2){
					g.setColor(Color.YELLOW);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the space has been clicked and there was a "miss"
				if(spottype[k][i][j] == 7){
					g.setColor(Color.BLUE);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the space has been clicked and there was a "hit"
				if(spottype[k][i][j] == 4){
					g.setColor(Color.RED);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
//if the box contains a sunk ship
				if(spottype[k][i][j] == 5){
					g.setColor(Color.BLACK);
					g.fillRect(i*25, (j*25)+200, 25, 25);
				}
			}
		}
//draw the lines on the display to seperate each box from one another
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					g.setColor(Color.BLACK);
					g.drawRect(i*25, (j*25)+200, 25, 25);
				}
			}
		}
		
	}
	
//paint the boxes of your opponents boats on the display
	public void paintgameme(int k)
	{
		Graphics g = canvas.getGraphics();
//if its a one player game then display whether its the players turn or the computers turn
		if(oneplayergame == true){
		if(player == 0){
			g.setColor(Color.BLACK);
			g.drawString("Player 1's turn", 0, 10);
		}
		if(player == 1){
			g.setColor(Color.BLACK);
			g.drawString("Computer's turn", 0, 10);
		}
		}
//if its a two player game then display whetehr its player 1's turn or player 2's turn
		if(twoplayergame == true){
			if(player == 0){
				g.setColor(Color.BLACK);
				g.drawString("Player 1's turn", 0, 10);
			}
			if(player == 1){
				g.setColor(Color.BLACK);
				g.drawString("Player 2's turn", 0, 10);
			}
		}
		
//for every box on the display, color in the correct color for what the activity is on that box
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
//if a box has not been clicked
				if(clicked[k][i][j] == 0){
					g.setColor(Color.CYAN);
					g.fillRect((i*20)+275, (j-1)*20, 20, 20);
				}
//if a box is an edge
				if(spottype[k][i][j] == 1){
					g.setColor(Color.WHITE);
					g.fillRect((i*20)+275, (j-1)*20, 20, 20);
				}
//if a box has been clicked and it is a "miss"
				if((spottype[k][i][j] == 7) && (clicked[k][i][j] == 1)){
					g.setColor(Color.BLUE);
					g.fillRect((i*20)+275, (j-1)*20, 20, 20);
				}
//if a box has been clicked and it is a "hit"
				if((spottype[k][i][j] == 4) && (clicked[k][i][j] == 1)){
					g.setColor(Color.RED);
					g.fillRect((i*20)+275, (j-1)*20, 20, 20);
				}
//if a box has been clicked and the boat has been sunk
				if((spottype[k][i][j] == 5) && (clicked[k][i][j] == 1)){
					g.setColor(Color.BLACK);
					g.fillRect((i*20)+275, (j-1)*20, 20, 20);
				}
			}
		}
//draw the lines on the display to seperate each box from one another
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					g.setColor(Color.BLACK);
					g.drawRect((i*20)+275, (j-1)*20, 20, 20);
				}
			}
		}
		
	}

//function to place boats individually	
	public void placeboats(int k)
	{
		Graphics g = canvas.getGraphics();
//re-initialize box activity
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
//if box is not an edge, make it unclicked and make it no activity
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					clicked[k][i][j] = 0;
					spottype[k][i][j] = 0;
				}
				else{
					clicked[k][i][j] = 1;
					spottype[k][i][j] = 1;
				}
			}
		}
//clear the screen and re-display new display		
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, 550, 600);
		paint(k);

//keep count how many 4 space boats have been placed		
		int a = 0;
//keep count how many 3 space boats have been placed
		int b = 0;
//keep count how many 2 space boats have been placed
		int c = 0;
//keep count how many 1 space boats have been placed
		int d = 0;
//keep count how many 4 space boats have been placed correctly based on horizontal/vertical option
		int aa = 0;
//keep count how many 3 space boats have been placed correctly based on horizontal/vertical option
		int bb = 0;
//keep count how many 2 space boats have been placed correctly based on horizontal/vertical option
		int cc = 0;

		while(a < 1){
//display messages and store it in variables
			int s = Integer.parseInt(JOptionPane.showInputDialog(null, "write the x coordinate (from 1 to 10) of the box you want to place the front end of the boat of length 4"));
			int t = Integer.parseInt(JOptionPane.showInputDialog(null, "write the y coordinate (from 1 to 10) of the box you want to place the front end of the boat of length 4"));
			int p = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			while(aa < 1){
			if((p != 0) && (p != 1)){
				JOptionPane.showMessageDialog(null, "That wasnt a 0 or a 1");
//re-display the message if p wasnt a 0 or a 1
				p = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			}
//if p was a 0 or a 1 then move on
			else{
				aa++;
			}
			}
//if p was horizontal
			if(p == 0){
//if the 4 spaces you want the boat in is available, then make the space clicked, followed by the 3 spaces 
//to the right of that box, a 2 (saying a boat has been placed there)
//and make the spaces around those spaces a 3 (saying there is a boat next to those spaces)
				if((spottype[k][s][t] == 0) && (spottype[k][s+1][t] == 0) && (spottype[k][s+2][t] == 0) && (spottype[k][s+3][t] == 0)){
				spottype[k][s][t] = 2;
				spottype[k][s+1][t] = 2;
				spottype[k][s+2][t] = 2;
				spottype[k][s+3][t] = 2;
				XcoorFourBoat[a][k][s][t] = 2;
				XcoorFourBoat[a][k][s+1][t] = 2;
				XcoorFourBoat[a][k][s+2][t] = 2;
				XcoorFourBoat[a][k][s+3][t] = 2;
				spottype[k][s-1][t] = 3;
				spottype[k][s+4][t] = 3;
				spottype[k][s][t+1] = 3;
				spottype[k][s][t-1] = 3;
				spottype[k][s+1][t+1] = 3;
				spottype[k][s+1][t-1] = 3;
				spottype[k][s+2][t+1] = 3;
				spottype[k][s+2][t-1] = 3;
				spottype[k][s+3][t+1] = 3;
				spottype[k][s+3][t-1] = 3;
				spottype[k][s-1][t+1] = 3;
				spottype[k][s-1][t-1] = 3;
				spottype[k][s+4][t+1] = 3;
				spottype[k][s+4][t-1] = 3;
				a++;
//clear the display and re-display the new display
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paint(k);
				}
//if the 4 spaces you want the boat in is not available, then tell them to pick again
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
//if p is vertical, do the same thing as horizontal, only in the vertical direction
			else{
				if((spottype[k][s][t] == 0) && (spottype[k][s][t+1] == 0) && (spottype[k][s][t+2] == 0) && (spottype[k][s][t+3] == 0)){
					spottype[k][s][t] = 2;
					spottype[k][s][t+1] = 2;
					spottype[k][s][t+2] = 2;
					spottype[k][s][t+3] = 2;
					XcoorFourBoat[a][k][s][t] = 2;
					XcoorFourBoat[a][k][s][t+1] = 2;
					XcoorFourBoat[a][k][s][t+2] = 2;
					XcoorFourBoat[a][k][s][t+3] = 2;
					spottype[k][s][t-1] = 3;
					spottype[k][s][t+4] = 3;
					spottype[k][s-1][t-1] = 3;
					spottype[k][s-1][t] = 3;
					spottype[k][s-1][t+1] = 3;
					spottype[k][s-1][t+2] = 3;
					spottype[k][s-1][t+3] = 3;
					spottype[k][s-1][t+4] = 3;
					spottype[k][s+1][t-1] = 3;
					spottype[k][s+1][t] = 3;
					spottype[k][s+1][t+1] = 3;
					spottype[k][s+1][t+2] = 3;
					spottype[k][s+1][t+3] = 3;
					spottype[k][s+1][t+4] = 3;
					a++;
					g.setColor(Color.WHITE);
					g.fillRect(0, 0, 550, 600);
					paint(k);
				}
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
		}
//place 2 boats of length 3 (same thing as for the 4 boat)
		while(b < 2){
			int u = Integer.parseInt(JOptionPane.showInputDialog(null, "write the x coordinate (from 1 to 10) of the box you want to place the front end of the " + (b + 1) + " of 2 boats of length 3"));
			int v = Integer.parseInt(JOptionPane.showInputDialog(null, "write the y coordinate (from 1 to 10) of the box you want to place the front end of the " + (b + 1) + " of 2 boats of length 3"));
			int q = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			while(bb < 1){
			if((q != 0) && (q != 1)){
				JOptionPane.showMessageDialog(null, "That wasnt a 0 or a 1");
				q = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			}
			else{
				bb++;
			}
			}
			if(q == 0){
				if((spottype[k][u][v] == 0) && (spottype[k][u+1][v] == 0) && (spottype[k][u+2][v] == 0)){
				spottype[k][u][v] = 2;
				spottype[k][u+1][v] = 2;
				spottype[k][u+2][v] = 2;
				XcoorThreeBoat[b][k][u][v] = 2;
				XcoorThreeBoat[b][k][u+1][v] = 2;
				XcoorThreeBoat[b][k][u+2][v] = 2;
				spottype[k][u][v+1] = 3;
				spottype[k][u][v-1] = 3;
				spottype[k][u+1][v+1] = 3;
				spottype[k][u+1][v-1] = 3;
				spottype[k][u+2][v+1] = 3;
				spottype[k][u+2][v-1] = 3;
				spottype[k][u-1][v+1] = 3;
				spottype[k][u-1][v-1] = 3;
				spottype[k][u-1][v] = 3;
				spottype[k][u+3][v+1] = 3;
				spottype[k][u+3][v-1] = 3;
				spottype[k][u+3][v] = 3;
				b++;
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paint(k);
				}
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
			else{
				if((spottype[k][u][v] == 0) && (spottype[k][u][v+1] == 0) && (spottype[k][u][v+2] == 0)){
					spottype[k][u][v] = 2;
					spottype[k][u][v+1] = 2;
					spottype[k][u][v+2] = 2;
					XcoorThreeBoat[b][k][u][v] = 2;
					XcoorThreeBoat[b][k][u][v+1] = 2;
					XcoorThreeBoat[b][k][u][v+2] = 2;
					spottype[k][u][v-1] = 3;
					spottype[k][u][v+3] = 3;
					spottype[k][u-1][v-1] = 3;
					spottype[k][u-1][v] = 3;
					spottype[k][u-1][v+1] = 3;
					spottype[k][u-1][v+2] = 3;
					spottype[k][u-1][v+3] = 3;
					spottype[k][u+1][v-1] = 3;
					spottype[k][u+1][v] = 3;
					spottype[k][u+1][v+1] = 3;
					spottype[k][u+1][v+2] = 3;
					spottype[k][u+1][v+3] = 3;
					b++;
					g.setColor(Color.WHITE);
					g.fillRect(0, 0, 550, 600);
					paint(k);
				}
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
		}
//place 3 boats of length 2 (same thing as the 4 boat)
		while(c < 3){
			int w = Integer.parseInt(JOptionPane.showInputDialog(null, "write the x coordinate (from 1 to 10) of the box you want to place the front end of the " + (c + 1) + " of 3 boats of length 2"));
			int x = Integer.parseInt(JOptionPane.showInputDialog(null, "write the y coordinate (from 1 to 10) of the box you want to place the front end of the " + (c + 1) + " of 3 boats of length 2"));
			int r = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			while(cc < 1){
			if((r != 0) && (r != 1)){
				JOptionPane.showMessageDialog(null, "That wasnt a 0 or a 1");
				r = Integer.parseInt(JOptionPane.showInputDialog(null, "Horizontal (0) or Vertical (1) ?"));
			}
			else{
				cc++;
			}
			}
			if(r == 0){
				if((spottype[k][w][x] == 0) && (spottype[k][w+1][x] == 0)){
				spottype[k][w][x] = 2;
				spottype[k][w+1][x] = 2;
				XcoorTwoBoat[c][k][w][x] = 2;
				XcoorTwoBoat[c][k][w+1][x] = 2;
				spottype[k][w][x+1] = 3;
				spottype[k][w][x-1] = 3;
				spottype[k][w+1][x+1] = 3;
				spottype[k][w+1][x-1] = 3;
				spottype[k][w-1][x+1] = 3;
				spottype[k][w-1][x-1] = 3;
				spottype[k][w-1][x] = 3;
				spottype[k][w+2][x+1] = 3;
				spottype[k][w+2][x-1] = 3;
				spottype[k][w+2][x] = 3;
				c++;
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paint(k);
				}
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
			else{
				if((spottype[k][w][x] == 0) && (spottype[k][w][x+1] == 0)){
					spottype[k][w][x] = 2;
					spottype[k][w][x+1] = 2;
					XcoorTwoBoat[c][k][w][x] = 2;
					XcoorTwoBoat[c][k][w][x+1] = 2;
					spottype[k][w][x-1] = 3;
					spottype[k][w][x+2] = 3;
					spottype[k][w-1][x-1] = 3;
					spottype[k][w-1][x] = 3;
					spottype[k][w-1][x+1] = 3;
					spottype[k][w-1][x+2] = 3;
					spottype[k][w+1][x-1] = 3;
					spottype[k][w+1][x] = 3;
					spottype[k][w+1][x+1] = 3;
					spottype[k][w+1][x+2] = 3;
					c++;
					g.setColor(Color.WHITE);
					g.fillRect(0, 0, 550, 600);
					paint(k);
				}
				else{
					JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
				}
			}
		}
//place 4 boats of length 1 (same thing as the 4 boat, except no horizontal/vertical because the boat length is only 1 box)
		while(d < 4){
			int y = Integer.parseInt(JOptionPane.showInputDialog(null, "write the x coordinate (from 1 to 10) of the box you want to place the front end of the " + (d + 1) + " of 4 boats of length 1"));
			int z = Integer.parseInt(JOptionPane.showInputDialog(null, "write the y coordinate (from 1 to 10) of the box you want to place the front end of the " + (d + 1) + " of 4 boats of length 1"));
			if((spottype[k][y][z] == 0)){
				spottype[k][y][z] = 2;
				XcoorOneBoat[d][k][y][z] = 2;
				spottype[k][y][z+1] = 3;
				spottype[k][y][z-1] = 3;
				spottype[k][y+1][z+1] = 3;
				spottype[k][y+1][z-1] = 3;
				spottype[k][y-1][z+1] = 3;
				spottype[k][y-1][z-1] = 3;
				spottype[k][y+1][z] = 3;
				spottype[k][y-1][z] = 3;
				d++;
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paint(k);
			}
			else{
				JOptionPane.showMessageDialog(null, "A boat can not be placed there, try again.");
			}
		}
//during the process of placing boats, the edge's might have become colored, so make the edges 1 again 
//so that they will be painted white
		for(int m = 0; m < 12; m++){
			for(int n = 0; n < 12; n++){
				if((m == 0) || (m == 11) || (n == 0) || (n == 11)){
					clicked[k][m][n] = 1;
					spottype[k][m][n] = 1;
				}
			}
			}
		
	}

//when buttons are clicked
	public void actionPerformed(ActionEvent e) {
		Graphics g = canvas.getGraphics();
//when the back button is clicked, clear the screen, and re-display the start screen
//make the back button disappear and make the instruction, 1 player, and 2 players buttons reappear
		if(e.getSource() == backButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			oneButton.setVisible(true);
			twoButton.setVisible(true);
			instructButton.setVisible(true);
			backButton.setVisible(false);
			g.setColor(Color.BLACK);
			g.drawString("BATTLESHIP", 200, 250);
		}
//when the instruction button is clicked, clear the screen, and display the instruction of the game
//make the instruction, 1 player, and 2 players buttons disappear, and make the back button appear
		if(e.getSource() == instructButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			oneButton.setVisible(false);
			twoButton.setVisible(false);
			instructButton.setVisible(false);
			backButton.setVisible(true);
			g.setColor(Color.BLACK);
			g.drawString("Rules:\n\n", 0, 20);
			g.drawString("1. Players take turns attempting to get a 'hit' on one of their opponent's ships.", 0, 40);
			g.drawString("2. The player, in turn, clicks one square on his opponent's grid at which to shoot.", 0, 60);
			g.drawString("3. If the first selection is a hit, he or she may continue selecting coordinates until they miss.", 0, 80);
			g.drawString("When all the squares a ship is covering have been hit, that ship is considered sunk.\n", 15, 95);
			g.drawString("4. The first person to successfully sink all of his opponent's ships are placed wins the", 0, 115);
			g.drawString("game.", 15, 130);
		}
//when this button is clicked, make the instruction, 1 player, and 2 players buttons disappear, and make
//the randomize and place boats buttons appear, also clear screen and paint the empty board display so the 
//player can place boats also randomly place computers boats
		if(e.getSource() == oneButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			oneButton.setVisible(false);
			twoButton.setVisible(false);
			instructButton.setVisible(false);
			randomizeButton.setVisible(true);
			placeButton.setVisible(true);
			randomlyplaceboats(1);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Place your boats\n", 0, 10);
		}
//when this button is clicked, make the instruction, 1 player, and 2 players buttons disappear, and make
//the randomize and place boats buttons appear, also clear screen and paint the empty board display so 
//player 1 can place boats
		if(e.getSource() == twoButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			oneButton.setVisible(false);
			twoButton.setVisible(false);
			instructButton.setVisible(false);
			randomizeoneButton.setVisible(true);
			placeoneButton.setVisible(true);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Player 1 place your boats\n", 0, 10);
		}
//when this button is clicked, make every button disappear, clear screen and display your board of boats
//and display your opponents empty clickable board
		if(e.getSource() == startButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			startButton.setVisible(false);
			randomizeButton.setVisible(false);
			placeButton.setVisible(false);
			paintgameyou(0);
			paintgameme(1);
			oneplayergame = true;
			//g.setColor(Color.BLACK);
			//g.drawString("Player 1's turn", 0, 10);
		}
//when this button is clicked, make every button disappear, make buttons randomize and place boats for 
//player 2 appear, also clear screen, and display player 2's empty board so they are able to place boats
		if(e.getSource() == startoneButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			startoneButton.setVisible(false);
			randomizeoneButton.setVisible(false);
			randomizetwoButton.setVisible(true);
			placeoneButton.setVisible(false);
			placetwoButton.setVisible(true);
			paint(1);
			g.setColor(Color.BLACK);
			g.drawString("Player 2 place your boats\n", 0, 10);
		}
//when this button is clicked, make every button disappear, clear screen and display player 1's board of 
//boats and display player 2's empty clickable board
		if(e.getSource() == starttwoButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			starttwoButton.setVisible(false);
			randomizetwoButton.setVisible(false);
			placetwoButton.setVisible(false);
			paintgameyou(0);
			paintgameme(1);
			twoplayergame = true;
			//g.setColor(Color.BLACK);
			//g.drawString("Player 1's turn", 0, 10);
		}
//when this button is clicked, clear the screen, and redisplay the board with the boats randomly placed
		if(e.getSource() == randomizeButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			randomlyplaceboats(0);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Place your boats\n", 0, 10);
			startButton.setVisible(true);

		}
//when this button is clicked, clear the screen, and redisplay the board with player 1's boats randomly 
//placed
		if(e.getSource() == randomizeoneButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			randomlyplaceboats(0);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Player 1 place your boats\n", 0, 10);
			startoneButton.setVisible(true);
		}
//when this button is clicked, clear the screen, and redisplay the board with player 2's boats randomly 
//placed
		if(e.getSource() == randomizetwoButton){
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			randomlyplaceboats(1);
			paint(1);
			g.setColor(Color.BLACK);
			g.drawString("Player 2 place your boats\n", 0, 10);
			starttwoButton.setVisible(true);
		}
//when this button is clicked, clear the screen, and start the function to place boats, when thats done 
//then redisplay the board
		if(e.getSource() == placeButton){
			startButton.setVisible(true);
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			placeboats(0);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Place your boats\n", 0, 10);
		}
//when this button is clicked, clear the screen, and start the function to place player 1's boats, when 
//thats done then redisplay player 1's board
		if(e.getSource() == placeoneButton){
			startoneButton.setVisible(true);
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			placeboats(0);
			paint(0);
			g.setColor(Color.BLACK);
			g.drawString("Player 1 place your boats\n", 0, 10);
		}
//when this button is clicked, clear the screen, and start the function to place player 2's boats, when 
//thats done then redisplay player 2's board
		if(e.getSource() == placetwoButton){
			starttwoButton.setVisible(true);
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 550, 600);
			placeboats(1);
			paint(1);
			g.setColor(Color.BLACK);
			g.drawString("Player 2 place your boats\n", 0, 10);
		}
	}

//function to see if there is a winner and to determine who that winner is
	public void determinewinner(){
//determine if there is a winner
		Graphics g = canvas.getGraphics();
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, 50, 50);
		int boatone = 0;
		int boattwo = 0;
//for both players, if there is still a boat on the board and it is not "hit" or sunk, then increment by 1
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if(spottype[0][i][j] == 2){
					boatone++;
				}
				if(spottype[1][i][j] == 2){
					boattwo++;
				}
			}
		}
//if there are no boats on player 1's board then they are the winner
		if(boatone < 1){
			g.setColor(Color.BLACK);
			g.drawString("Player 1 is the winner", 0, 10);
		}
//if there are no boats on player 2's (two player game) or the computer's (one player game) board then 
//they are the winner
		else if(boattwo < 1){
			if(twoplayergame == true){
				g.setColor(Color.BLACK);
				g.drawString("Player 2 is the winner", 0, 10);
			}
			else if(oneplayergame == true){
				g.setColor(Color.BLACK);
				g.drawString("Computer is the winner", 0, 10);
			}
		}
	}

//when mouse is clicked do the following	
	public void mouseClicked(MouseEvent e)
	{
//get the graphics so that stuff will appear on the applet
		Graphics g = canvas.getGraphics();
//get the X and Y position of where you clicked
		int x = e.getX();
		int y = e.getY();
//if its a one player game		
		if(oneplayergame == true){
			int check = 0;
//if its player 1's turn
			if(player == 0){
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
//if the click is in a certain box
						if ((x >= (Xstart[i][j])) && (x <= (Xend[i][j])) && (y >= (Ystart[i][j])) && (y <= (Yend[i][j])) && (clicked[1][i][j] == 0))
						{
//if that box has a boat in it, then make it clicked and a "hit" (still player 1's turn)
							if(spottype[1][i][j] == 2){
								spottype[1][i][j] = 4;
								clicked[1][i][j] = 1;
							}
//if that box does not have a boat in it, then make it clicked and a "miss", and make it player 2's turn
							else{
								spottype[1][i][j] = 7;
								clicked[1][i][j] = 1;
								player = 1;
							}
						}
					}
				}
//if all sections of the 4 boat are hit, turn it black, and turn every spot around the boat to clicked
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorFourBoat[0][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 4){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorFourBoat[0][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
//if all sections of either of the 2 3-boats are hit, turn it black, and turn every spot around the boat 
//to clicked
				int b = 0;
				while(b < 2){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorThreeBoat[b][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 3){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorThreeBoat[b][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				b++;
				}
//if all sections of either of the 3 2-boats are hit, turn it black, and turn every spot around the boat 
//to clicked				
				int c = 0;
				while(c < 3){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorTwoBoat[c][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 2){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorTwoBoat[c][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				c++;
				}
//if all sections of either of the 4 1-boats are hit, turn it black, and turn every spot around the boat 
//to clicked				
				int d = 0;
				while(d < 4){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorOneBoat[d][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 1){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorOneBoat[d][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				d++;
				}
//clear screen, re-display new display and use the determinewinner function to see if there is a winner 
//after current turn				
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paintgameyou(0);
				paintgameme(1);
				determinewinner();
			}
//if player is computer, do the same thing as player 1, except spot is randomly determined instead of clicked
			if (player == 1){
				//comp
				 int pick = 0;
				 while(pick < 1){
				 	int i = (int) ((Math.random()*100)%11);
				 	int j = (int) ((Math.random()*200)%11);
						if ((clicked[0][i][j] == 0))
						{
							if(spottype[0][i][j] == 2){
								spottype[0][i][j] = 4;
								clicked[0][i][j] = 1;
							}
							else{
								spottype[0][i][j] = 7;
								clicked[0][i][j] = 1;
								pick++;
								player = 0;
							}
						}
				}
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorFourBoat[0][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 4){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorFourBoat[0][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				int b = 0;
				while(b < 2){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorThreeBoat[b][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 3){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorThreeBoat[b][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				b++;
				}
				
				int c = 0;
				while(c < 3){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorTwoBoat[c][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 2){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorTwoBoat[c][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				c++;
				}
				
				int d = 0;
				while(d < 4){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorOneBoat[d][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 1){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorOneBoat[d][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				d++;
				}
				
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paintgameyou(0);
				paintgameme(1);
				determinewinner();
			}
		}

//same thing as a 1 player game, except all moves are made by clicking (since there is no computer)		
		if(twoplayergame == true){
			int check = 0;
			if(player == 0){
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if ((x >= (Xstart[i][j])) && (x <= (Xend[i][j])) && (y >= (Ystart[i][j])) && (y <= (Yend[i][j])) && (clicked[1][i][j] == 0))
						{
							if(spottype[1][i][j] == 2){
								spottype[1][i][j] = 4;
								clicked[1][i][j] = 1;
							}
							else{
								spottype[1][i][j] = 7;
								clicked[1][i][j] = 1;
								player = 1;
							}
						}
					}
				}

				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorFourBoat[0][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 4){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorFourBoat[0][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				int b = 0;
				while(b < 2){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorThreeBoat[b][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 3){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorThreeBoat[b][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				b++;
				}
				
				int c = 0;
				while(c < 3){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorTwoBoat[c][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 2){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorTwoBoat[c][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				c++;
				}
				
				int d = 0;
				while(d < 4){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorOneBoat[d][1][i][j] == 2) && (spottype[1][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 1){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorOneBoat[d][1][i][j] == 2)){
								spottype[1][i][j] = 5;
								if(clicked[1][i][j+1] != 1){
									spottype[1][i][j+1] = 7;
									clicked[1][i][j+1] = 1;
								}
								if(clicked[1][i][j-1] != 1){
									spottype[1][i][j-1] = 7;
									clicked[1][i][j-1] = 1;
								}
								if(clicked[1][i-1][j-1] != 1){
									spottype[1][i-1][j-1] = 7;
									clicked[1][i-1][j-1] = 1;
								}
								if(clicked[1][i-1][j] != 1){
									spottype[1][i-1][j] = 7;
									clicked[1][i-1][j] = 1;
								}
								if(clicked[1][i-1][j+1] != 1){
									spottype[1][i-1][j+1] = 7;
									clicked[1][i-1][j+1] = 1;
								}
								if(clicked[1][i+1][j-1] != 1){
									spottype[1][i+1][j-1] = 7;
									clicked[1][i+1][j-1] = 1;
								}
								if(clicked[1][i+1][j] != 1){
									spottype[1][i+1][j] = 7;
									clicked[1][i+1][j] = 1;
								}
								if(clicked[1][i+1][j+1] != 1){
									spottype[1][i+1][j+1] = 7;
									clicked[1][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				d++;
				}
//clear screen				
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
//switch boards, make board that was clickable into the display board, and make display board 
//into clickable board
				paintgameyou(player);
				paintgameme((player+1)%2);
				determinewinner();
			}
//for player 2 in a 2 player game
			else{
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if ((x >= (Xstart[i][j])) && (x <= (Xend[i][j])) && (y >= (Ystart[i][j])) && (y <= (Yend[i][j])) && (clicked[0][i][j] == 0))
						{
							if(spottype[0][i][j] == 2){
								spottype[0][i][j] = 4;
								clicked[0][i][j] = 1;
							}
							else{
								spottype[0][i][j] = 7;
								clicked[0][i][j] = 1;
								player = 0;
							}
						}
					}
				}
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorFourBoat[0][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 4){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorFourBoat[0][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				int b = 0;
				while(b < 2){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorThreeBoat[b][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 3){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorThreeBoat[b][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				b++;
				}
				
				int c = 0;
				while(c < 3){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorTwoBoat[c][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 2){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorTwoBoat[c][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				c++;
				}
				
				int d = 0;
				while(d < 4){
				check = 0;
				for(int i = 0; i < 12; i++){
					for(int j = 0; j < 12; j++){
						if((XcoorOneBoat[d][0][i][j] == 2) && (spottype[0][i][j] == 4)){
							check++;
						}
					}
				}
				if(check == 1){
					for(int i = 0; i < 12; i++){
						for(int j = 0; j < 12; j++){
							if((XcoorOneBoat[d][0][i][j] == 2)){
								spottype[0][i][j] = 5;
								if(clicked[0][i][j+1] != 1){
									spottype[0][i][j+1] = 7;
									clicked[0][i][j+1] = 1;
								}
								if(clicked[0][i][j-1] != 1){
									spottype[0][i][j-1] = 7;
									clicked[0][i][j-1] = 1;
								}
								if(clicked[0][i-1][j-1] != 1){
									spottype[0][i-1][j-1] = 7;
									clicked[0][i-1][j-1] = 1;
								}
								if(clicked[0][i-1][j] != 1){
									spottype[0][i-1][j] = 7;
									clicked[0][i-1][j] = 1;
								}
								if(clicked[0][i-1][j+1] != 1){
									spottype[0][i-1][j+1] = 7;
									clicked[0][i-1][j+1] = 1;
								}
								if(clicked[0][i+1][j-1] != 1){
									spottype[0][i+1][j-1] = 7;
									clicked[0][i+1][j-1] = 1;
								}
								if(clicked[0][i+1][j] != 1){
									spottype[0][i+1][j] = 7;
									clicked[0][i+1][j] = 1;
								}
								if(clicked[0][i+1][j+1] != 1){
									spottype[0][i+1][j+1] = 7;
									clicked[0][i+1][j+1] = 1;
								}
							}
						}
					}
				}
				d++;
				}
//same as player 1 in a 2 player game				
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, 550, 600);
				paintgameyou(player);
				paintgameme((player+1)%2);
				determinewinner();
			}
		}

	}
	
//add these following unused methods needed for Mouse Listener without making class Battle abstract	
	public void mouseEntered(MouseEvent e) 
	{
		
	}

	public void mouseExited(MouseEvent e) 
	{

	}

	public void mousePressed(MouseEvent e) 
	{
		
	}

	public void mouseReleased(MouseEvent e) 
	{
		
	}
	
	//function does the same thing as placeboats function, but it replaces the user input with random numbers	
	public void randomlyplaceboats(int k)
	{
//re-initialize
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if((i != 0) && (i != 11) && (j != 0) && (j != 11)){
					clicked[k][i][j] = 0;
					spottype[k][i][j] = 0;
				}
				else{
					clicked[k][i][j] = 1;
					spottype[k][i][j] = 1;
				}
			}
		}
		
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		
//horizontal = 0
//vertical = 1
		
//place 1 boat of length 4
		while(a < 1){
			int s = (int) ((Math.random()*100)%11);
			int t = (int) ((Math.random()*200)%11);
			int p = (int) ((Math.random()*300)%2);
			if(p == 0){
			if((spottype[k][s][t] == 0) && (spottype[k][s+1][t] == 0) && (spottype[k][s+2][t] == 0) && (spottype[k][s+3][t] == 0)){
				spottype[k][s][t] = 2;
				spottype[k][s+1][t] = 2;
				spottype[k][s+2][t] = 2;
				spottype[k][s+3][t] = 2;
				XcoorFourBoat[a][k][s][t] = 2;
				XcoorFourBoat[a][k][s+1][t] = 2;
				XcoorFourBoat[a][k][s+2][t] = 2;
				XcoorFourBoat[a][k][s+3][t] = 2;
				spottype[k][s-1][t] = 3;
				spottype[k][s+4][t] = 3;
				spottype[k][s][t+1] = 3;
				spottype[k][s][t-1] = 3;
				spottype[k][s+1][t+1] = 3;
				spottype[k][s+1][t-1] = 3;
				spottype[k][s+2][t+1] = 3;
				spottype[k][s+2][t-1] = 3;
				spottype[k][s+3][t+1] = 3;
				spottype[k][s+3][t-1] = 3;
				spottype[k][s-1][t+1] = 3;
				spottype[k][s-1][t-1] = 3;
				spottype[k][s+4][t+1] = 3;
				spottype[k][s+4][t-1] = 3;
				a++;
			}
			}
			else{
				if((spottype[k][s][t] == 0) && (spottype[k][s][t+1] == 0) && (spottype[k][s][t+2] == 0) && (spottype[k][s][t+3] == 0)){
					spottype[k][s][t] = 2;
					spottype[k][s][t+1] = 2;
					spottype[k][s][t+2] = 2;
					spottype[k][s][t+3] = 2;
					XcoorFourBoat[a][k][s][t] = 2;
					XcoorFourBoat[a][k][s][t+1] = 2;
					XcoorFourBoat[a][k][s][t+2] = 2;
					XcoorFourBoat[a][k][s][t+3] = 2;
					spottype[k][s][t-1] = 3;
					spottype[k][s][t+4] = 3;
					spottype[k][s-1][t-1] = 3;
					spottype[k][s-1][t] = 3;
					spottype[k][s-1][t+1] = 3;
					spottype[k][s-1][t+2] = 3;
					spottype[k][s-1][t+3] = 3;
					spottype[k][s-1][t+4] = 3;
					spottype[k][s+1][t-1] = 3;
					spottype[k][s+1][t] = 3;
					spottype[k][s+1][t+1] = 3;
					spottype[k][s+1][t+2] = 3;
					spottype[k][s+1][t+3] = 3;
					spottype[k][s+1][t+4] = 3;
					a++;
				}
			}
		}
//place 2 boats of length 3
		while(b < 2){
			int u = (int) ((Math.random()*100)%11);
			int v = (int) ((Math.random()*200)%11);
			int q = (int) ((Math.random()*300)%2);
			if(q == 0){
			if((spottype[k][u][v] == 0) && (spottype[k][u+1][v] == 0) && (spottype[k][u+2][v] == 0)){
				spottype[k][u][v] = 2;
				spottype[k][u+1][v] = 2;
				spottype[k][u+2][v] = 2;
				XcoorThreeBoat[b][k][u][v] = 2;
				XcoorThreeBoat[b][k][u+1][v] = 2;
				XcoorThreeBoat[b][k][u+2][v] = 2;
				spottype[k][u][v+1] = 3;
				spottype[k][u][v-1] = 3;
				spottype[k][u+1][v+1] = 3;
				spottype[k][u+1][v-1] = 3;
				spottype[k][u+2][v+1] = 3;
				spottype[k][u+2][v-1] = 3;
				spottype[k][u-1][v+1] = 3;
				spottype[k][u-1][v-1] = 3;
				spottype[k][u-1][v] = 3;
				spottype[k][u+3][v+1] = 3;
				spottype[k][u+3][v-1] = 3;
				spottype[k][u+3][v] = 3;
				b++;
			}
			}
			else{
				if((spottype[k][u][v] == 0) && (spottype[k][u][v+1] == 0) && (spottype[k][u][v+2] == 0)){
					spottype[k][u][v] = 2;
					spottype[k][u][v+1] = 2;
					spottype[k][u][v+2] = 2;
					XcoorThreeBoat[b][k][u][v] = 2;
					XcoorThreeBoat[b][k][u][v+1] = 2;
					XcoorThreeBoat[b][k][u][v+2] = 2;
					spottype[k][u][v-1] = 3;
					spottype[k][u][v+3] = 3;
					spottype[k][u-1][v-1] = 3;
					spottype[k][u-1][v] = 3;
					spottype[k][u-1][v+1] = 3;
					spottype[k][u-1][v+2] = 3;
					spottype[k][u-1][v+3] = 3;
					spottype[k][u+1][v-1] = 3;
					spottype[k][u+1][v] = 3;
					spottype[k][u+1][v+1] = 3;
					spottype[k][u+1][v+2] = 3;
					spottype[k][u+1][v+3] = 3;
					b++;
				}
			}
		}
//place 3 boats of length 2
		while(c < 3){
			int w = (int) ((Math.random()*100)%11);
			int x = (int) ((Math.random()*200)%11);
			int r = (int) ((Math.random()*300)%2);
			if(r == 0){
			if((spottype[k][w][x] == 0) && (spottype[k][w+1][x] == 0)){
				spottype[k][w][x] = 2;
				spottype[k][w+1][x] = 2;
				XcoorTwoBoat[c][k][w][x] = 2;
				XcoorTwoBoat[c][k][w+1][x] = 2;
				spottype[k][w][x+1] = 3;
				spottype[k][w][x-1] = 3;
				spottype[k][w+1][x+1] = 3;
				spottype[k][w+1][x-1] = 3;
				spottype[k][w-1][x+1] = 3;
				spottype[k][w-1][x-1] = 3;
				spottype[k][w-1][x] = 3;
				spottype[k][w+2][x+1] = 3;
				spottype[k][w+2][x-1] = 3;
				spottype[k][w+2][x] = 3;
				c++;
			}
			}
			else{
				if((spottype[k][w][x] == 0) && (spottype[k][w][x+1] == 0)){
					spottype[k][w][x] = 2;
					spottype[k][w][x+1] = 2;
					XcoorTwoBoat[c][k][w][x] = 2;
					XcoorTwoBoat[c][k][w][x+1] = 2;
					spottype[k][w][x-1] = 3;
					spottype[k][w][x+2] = 3;
					spottype[k][w-1][x-1] = 3;
					spottype[k][w-1][x] = 3;
					spottype[k][w-1][x+1] = 3;
					spottype[k][w-1][x+2] = 3;
					spottype[k][w+1][x-1] = 3;
					spottype[k][w+1][x] = 3;
					spottype[k][w+1][x+1] = 3;
					spottype[k][w+1][x+2] = 3;
					c++;
				}
			}
		}
//place 4 boats of length 1
		while(d < 4){
			int y = (int) ((Math.random()*100)%11);
			int z = (int) ((Math.random()*200)%11);
			if((spottype[k][y][z] == 0)){
				spottype[k][y][z] = 2;
				XcoorOneBoat[d][k][y][z] = 2;
				spottype[k][y][z+1] = 3;
				spottype[k][y][z-1] = 3;
				spottype[k][y+1][z+1] = 3;
				spottype[k][y+1][z-1] = 3;
				spottype[k][y-1][z+1] = 3;
				spottype[k][y-1][z-1] = 3;
				spottype[k][y+1][z] = 3;
				spottype[k][y-1][z] = 3;
				d++;
			}
		}
		for(int m = 0; m < 12; m++){
			for(int n = 0; n < 12; n++){
				if((m == 0) || (m == 11) || (n == 0) || (n == 11)){
					clicked[k][m][n] = 1;
					spottype[k][m][n] = 1;
				}
			}
			}
	}
	
}